package com.smart.imagecoupon.service;

import com.alibaba.fastjson.JSONArray;
import com.baidu.aip.imageclassify.AipImageClassify;
import com.smart.imagecoupon.bean.BaiduRep;
import com.smart.imagecoupon.bean.RepMessage;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class MessageService {


    public String getCoupon(BaiduRep baiduRep) throws IOException {
        if(baiduRep == null){
            return null;
        }
        StringBuffer stringBuffer = new StringBuffer();
        //stringBuffer.append("恭喜您获得");
        stringBuffer.append(baiduRep.getRoot());
        stringBuffer.append(":");
        stringBuffer.append(baiduRep.getKeyword());
        stringBuffer.append("优惠券");
        return stringBuffer.toString();
    }

    public RepMessage getRepMessage(String name){
        if(name == null){
            return RepMessage.builder()
                    .name("没有获得优惠券")
                    .build();
        }
        int[] nums = { 10, 15, 20, 30, 40, 50};
        int i = (int) (Math.random() * nums.length);
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("优惠")
                .append(nums[i])
                .append("元");
        return RepMessage.builder()
                .name(name)
                .message(stringBuffer.toString())
                .build();
    }

}
